home *** CD-ROM | disk | FTP | other *** search
- #
- # tcllib.test
- #
- # Tests for commands and functionallity involved in demand loadable Tcl
- # libraries.
- #---------------------------------------------------------------------------
- # Copyright 1992 Karl Lehenbauer and Mark Diekhans.
- #
- # Permission to use, copy, modify, and distribute this software and its
- # documentation for any purpose and without fee is hereby granted, provided
- # that the above copyright notice appear in all copies. Karl Lehenbauer and
- # Mark Diekhans make no representations about the suitability of this
- # software for any purpose. It is provided "as is" without express or
- # implied warranty.
- #------------------------------------------------------------------------------
- # $Id: tcllib.test,v 2.0 1992/10/16 04:50:17 markd Rel $
- #------------------------------------------------------------------------------
- #
-
- if {[info procs test] == ""} then {source testlib.tcl}
-
- rename SAVED_UNKNOWN unknown
- set SAVE_TCLPATH $TCLPATH
- set TCLPATH {}
- global TCLENV
- catch {unset auto_path}
-
- if {[id user] == "root"} {
- puts stderr "*************************************************************"
- puts stderr "You are running as `root', certain tcllib tests will be"
- puts stderr "skipped"
- puts stderr "*************************************************************"
- }
-
- #
- # Since we have libraries coming and going in this test, we need to
- # reset the environment. The file id that is used by the tcllib code
- # is based on inode, so if a library is purged, it might be recycled.
- #
- proc TclLibReset {} {
- global TCLENV
- foreach idx [array names TCLENV] {
- case $idx {
- {PROC:*} {unset TCLENV($idx)}
- {PKG:*} {unset TCLENV($idx)}
- {@*} {unset TCLENV($idx)}
- }
- }
- autoload buildidx.tcl buildpackageindex
- }
-
- proc TclLibCleanUp {} {
- catch {chmod +rwx tcllib1.dir}
- catch {chmod +rwx tcllib2.dir}
- unlink -nocomplain [glob -nocomplain tcllib1.dir/* tcllib1.dir/.*]
- unlink -nocomplain [glob -nocomplain tcllib2.dir/* tcllib2.dir/.*]
- catch {rmdir tcllib1.dir}
- catch {rmdir tcllib2.dir}
- TclLibReset
- }
-
- TclLibCleanUp
-
- proc PutFile {fileName args} {
- set fp [open $fileName w]
- foreach line $args {
- puts $fp $line
- }
- close $fp
- }
-
- catch {rename buildpackageindex {}} ;# Make sure we can autoload this
-
- #
- # Test parameter checking for the basic commands that are implemented
- # in C.
- #
-
- Test tcllib-1.1 {command parameter checking} {
- demand_load
- } 1 {wrong # args: demand_load procedure}
-
- Test tcllib-1.2 {command parameter checking} {
- demand_load a b c d
- } 1 {wrong # args: demand_load procedure}
-
- Test tcllib-1.3 {command parameter checking} {
- loadlibindex
- } 1 {wrong # args: loadlibindex libFile}
-
- Test tcllib-1.4 {command parameter checking} {
- loadlibindex a b c d
- } 1 {wrong # args: loadlibindex libFile}
-
- #
- # Test error recovery from bogus paths (should ignore path and not find proc)
- #
-
- Test tcllib-2.1 {bogus path test} {
- set TCLPATH [list /bogus/dir/path/no/work [pwd]/../tcllib]
- TclLibAAA
- } 1 {invalid command name: "TclLibAAA"}
-
- catch {rename buildpackageindex {}} ;# Make sure we can autoload this
-
- Test tcllib-2.2 {bogus path test} {
- set TCLPATH [list ~bogususerman/tcllib [pwd]/../tcllib]
- TclLibAAA
- } 1 {invalid command name: "TclLibAAA"}
-
- Test tcllib-2.3 {bogus path test} {
- set TCLPATH [pwd]/../tcllib
- set auto_path [list /bogus/dir/path/no/work]
- TclLibAAA
- } 1 {invalid command name: "TclLibAAA"}
-
-
- #
- # Test error recovery from bogus package library indices.
- #
-
- proc BuildTestLib {name {pbase TclLibAA}} {
- PutFile $name \
- "#@package: $name-package ${pbase}B ${pbase}C ${pbase}D" \
- "proc ${pbase}B {} {return \"***${pbase}B***\"}" \
- "proc ${pbase}C {} {return \"***${pbase}C***\"}" \
- "proc ${pbase}D {} {return \"***${pbase}D***\"}"
- }
-
- mkdir tcllib1.dir
- BuildTestLib tcllib1.dir/test1.tlib
- PutFile tcllib1.dir/test1.tndx {bogus
- data}
-
- set TCLPATH [list [pwd]/tcllib1.dir [pwd]/../tcllib]
-
- TestReg tcllib-3.1 {bogus package library index} {
- TclLibAAB
- } 1 {^format error in library index "/.*test1.tndx" \(bogus\)$}
-
- catch {rename buildpackageindex {}} ;# Make sure we can autoload this
-
- PutFile tcllib1.dir/test1.tndx \
- {test1-package 56 240 TclLibAAB TclLibAAC TclLibAAD}
-
- TestReg tcllib-3.2 {bogus package library index} {
- TclLibAAB
- } 1 {^range to eval outside of file bounds "/.*test1.tlib"$}
-
- PutFile tcllib1.dir/test1.tndx \
- {test1-package -1 140 TclLibAAB TclLibAAC TclLibAAD}
-
- TestReg tcllib-3.3 {bogus package library index} {
- TclLibAAB
- } 1 {^range to eval outside of file bounds "/.*test1.tlib"$}
-
- catch {rename buildpackageindex {}} ;# Make sure we can autoload this
-
- PutFile tcllib1.dir/test1.tndx \
- {test1-package 156 40 TclLibAAB TclLibAAC TclLibAAD}
-
- TestReg tcllib-3.4 {bogus package library index} {
- TclLibAAB
- } 1 {^range to eval outside of file bounds "/}
-
- set TCLPATH [list [pwd]/tcllib2.dir [pwd]/../tcllib]
-
- if {[id user] != "root"} {
- Test tcllib-4.1 {bad rebuild package library index} {
- global errorCode errorInfo
- mkdir tcllib2.dir
- BuildTestLib tcllib2.dir/test1.tlib TclLibAB
- chmod -w tcllib2.dir
- list [catch {TclLibABB} msg] [crange $msg 0 25] $TCLENV(inUnknown) \
- [lrange $errorCode 0 1] \
- [string match "*while loading Tcl package library*" $errorInfo] \
- [string match "*while demand loading \"TclLibABB\"*" $errorInfo]
- } 0 {1 {building package index for} 0 {UNIX EACCES} 1 1}
- }
-
- TclLibCleanUp
- mkdir tcllib1.dir
-
- set TCLPATH [list [pwd]/tcllib1.dir [pwd]/../tcllib]
-
- PutFile tcllib1.dir/tclIndex "#" "badline" "nukearray nukearray.tmp" \
- "baz baz.tmp"
-
- TestReg tcllib-5.1 {bogus Ousterhout library index} {
- nukearray
- } 1 {^format error in library index "/.*$}
-
- PutFile tcllib1.dir/tclIndex "#" "nukearray nukearray.tmp" "baz baz.tmp"
-
- TestReg tcllib-5.2 {missing file found with Ousterhout library index} {
- nukearray
- } 1 {couldn't read file}
-
- PutFile tcllib1.dir/nukearray.tmp {proc nukearray {} {}}
- chmod 000 tcllib1.dir/nukearray.tmp
-
- if {[id user] != "root"} {
- TestReg tcllib-5.3 {missing file found with Ousterhout library index} {
- nukearray
- } 1 {couldn't read file}
- }
-
- TclLibCleanUp
- mkdir tcllib1.dir
-
- BuildTestLib tcllib1.dir/test2.tlib TclLibAC
-
- PutFile tcllib1.dir/tclIndex "#" "nukearray nukearray.tmp" "baz baz.tmp"
- PutFile tcllib1.dir/nukearray.tmp {proc nukearray {} {return "@nukearray@"}}
-
- Test tcllib-6.1 {successful library access} {
- TclLibACB
- } 0 {***TclLibACB***}
-
- Test tcllib-6.2 {successful library access} {
- TclLibACB
- } 0 {***TclLibACB***}
-
- Test tcllib-6.3 {successful library access} {
- nukearray
- } 0 {@nukearray@}
-
- #
- # Test skipping of duplicate packages.
- #
- TclLibCleanUp
- mkdir {tcllib1.dir tcllib2.dir}
- set TCLPATH [list [pwd]/tcllib1.dir [pwd]/tcllib2.dir [pwd]/../tcllib]
-
- PutFile tcllib1.dir/test1.tlib \
- {#@package: test-pkg DupPkgTest} \
- {proc DupPkgTest {} {return {Version-1}}
- }
- PutFile tcllib2.dir/test2.tlib \
- {#@package: test-pkg DupPkgTest} \
- {proc DupPkgTest {} {return {Version-2}}
- }
-
- Test tcllib-7.1 {Duplicate package handling} {
- DupPkgTest
- } 0 {Version-1}
-
-
- TclLibCleanUp
-
- rename TclLibCleanUp {}
- rename PutFile {}
- rename TclLibReset {}
-
- set TCLPATH $SAVE_TCLPATH
- rename unknown SAVED_UNKNOWN
-
-
-